package com.weibo.blacklist.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.weibo.blacklist.BlackList;
import com.weibo.blacklist.service.BlackListService;
import com.weibo.blacklist.service.imp.BlackListServiceImp;
import com.weibo.common.CommonUtil;
import com.weibo.common.ValidateUserServlet;
import com.weibo.sql.CommonParm;
import com.weibo.user.User;

public class BlackListServlet extends ValidateUserServlet {
	private static Logger logger = Logger.getLogger(BlackListServlet.class);
	@Override
	public void doService(HttpServletRequest request,
			HttpServletResponse response) {
		// TODO Auto-generated method stub
		Object host_id = request.getParameter("host_id");
		if (host_id != null && !"".equals(host_id)) {
			BlackListService blackListService = new BlackListServiceImp();
			BlackList blackLis = new BlackList();
			User current_user = CommonUtil.getLoginUser(request);
			try {
				request.setCharacterEncoding("UTF-8");
				// response.setContentType("text/html;charset=UTF-8");
				response.setCharacterEncoding("UTF-8");
				PrintWriter out = response.getWriter();
				if (current_user != null) {
					blackLis.setUser_id(current_user.getUser_id());
					blackLis.setHost_id((String) host_id);
					out.print(blackListService.addBlack(blackLis));
				} else {
					out.print(CommonParm.LOGIN_TIMEOUT);
				}
				out.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				logger.error(e);
			}

		}

	}
}
